import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


public class HashcodeImpl {
	private static Map<Integer,byte[]> idMap = new LinkedHashMap<Integer,byte[]>();
	private static List<Integer> searchList = new ArrayList<Integer>();	
	
	public static void readFile(String fileName){
		FileInputStream fis = null;
		int idataBufferSize = 1024*1024*10;
		byte b;
		int byteBufSize = 32;
		byte[] word = new byte[byteBufSize];
		byte[] key = null;
		byte[] value = null;
		int byteBufCount=0;
		int completedCount =0;

		try{
			fis = new FileInputStream(new File(fileName));
			FileChannel fc = fis.getChannel();
			ByteBuffer byteBuf = ByteBuffer.allocate(idataBufferSize);
			int bytesRead = fc.read(byteBuf);
			int requestIdSize = searchList.size();
			
			while(bytesRead != -1){			
				byteBuf.flip();
				while(byteBuf.hasRemaining()){
					b = byteBuf.get();
					if(b == 44){
						key = word;
						word = new byte[byteBufSize];
						byteBufCount = 0;
						continue;
					}else if( b == 13 || b == 10){
						if(byteBufCount == 0){
							continue;
						}
						value = word;
						if(contains(Arrays.hashCode(key),value)){
							completedCount++;
							searchList.remove(Integer.valueOf(Arrays.hashCode(key)));
						}
						if(contains(Arrays.hashCode(value),key)){
							completedCount++;
							searchList.remove(Integer.valueOf(Arrays.hashCode(value)));
						}
						if(completedCount == requestIdSize){
							break;
						}
						word = new byte[byteBufSize];
						byteBufCount = 0;
						continue;
					}
					word[byteBufCount++]=b;
				}
				if(completedCount == requestIdSize){
					break;
				}
				byteBuf.clear();
				bytesRead = fc.read(byteBuf);			
			}			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				fis.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	private static boolean contains(int frames,byte[] value){
		
		for (Iterator<Integer> itr = searchList.iterator();itr.hasNext();) {
			int arr = itr.next().intValue();
			if(arr== frames){
				idMap.put(arr, value);
				return true;
			}
		}
		return false;
		
	}
	public static void main(String[] args) {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		char[] cbuf ; 

		// This is just a demo. You can use any logic here to read from stdin - till End of File or End of Stream etc.,
		cbuf = new char[1024] ;
		try {
			in.read(cbuf)  ;
		} catch (IOException e) {
			e.printStackTrace();
		}	finally	{
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		String inputs = new String(cbuf);
		args = inputs.split(" ");
		if(args == null) {
			System.out.print("FAILURE");
			System.exit(1);
		}
		if(args.length == 1) {
			File f = new File(args[0].trim());
			if(f.exists()){
				readFile(args[0].trim());
				System.out.print("READY");
				System.exit(0);
			}	else	{
				System.out.print("FAILURE");
				System.exit(1);
			}			
		}
		
		for (int i = 1; i < args.length; i++) {
			String arg = args[i].trim();
			if(arg.contains("T=") || arg.contains("R=")){
				String ids = arg.substring(arg.indexOf("=")+1);
				String[] idArr = ids.split(",");
				for (int j = 0; j < idArr.length; j++) {
					idMap.put(Arrays.hashCode(idArr[j].getBytes()),null);					
				}
			}
		}
		
		searchList.addAll(idMap.keySet());
		readFile(args[0].trim());
		int mapSize = idMap.size();
		int i =0;
		String output = "";
		for (Map.Entry<Integer, byte[]> entry:idMap.entrySet()) {
			byte[] value = entry.getValue();
			
			if(value == null){
				output = "FAILURE";
			}	else	{
				output = new String(value);
			}
			System.out.print(output);
			i++;
			
			if(i < mapSize)	{
				System.out.print(",");
			}				
		}
	}
}
//C:\\sivravis\\dev\\studies\\BOC2014\\codeContest1M.csv
//C:\sivravis\dev\studies\BOC2014\codeContest1M.csv
//C:\\sivravis\\dev\\studies\\BOC2014\\sampleInput.csv T=TXN00000000000000043179168899325,TXN00000000000000050209776656593 R=REF00000000000000116009591331268
//C:\\sivravis\\dev\\studies\\BOC2014\\codeContest1M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522
//C:\\sivravis\\dev\\studies\\BOC2014\\codeContest10M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522

//E:\\doc\\contest\\comviva\\codeContest1M.csv\\codeContest1M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522
